let { getTaskInfo, getProjectList } = require("../../../api/programs/forward");
let { getProjectDetail } = require("../../../api/programs/Detail.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    timeDown:true,

    xmstatus: false,
    xmmc: "",
    INFO: wx.getStorageSync("userInfoMy"),
    xmzList: [],
    query: {
      name: null,
      id: null,
      type: 77,
    },
    projectListTB: [],
    projectListGJ: [],
  },
  checkTime(){
    this.setData({
      timeDown:!this.data.timeDown
    })
    this.getProjectListAll()
  },
  onChange(e) {
    this.setData({
      xmmc: e.detail,
    });
  },
  onSearch() {
    this.getProjectListAll();
  },
  onClick() {
    this.getProjectListAll();
  },
  getProjectListAll() {
    this.setData({
      INFO: wx.getStorageSync("userInfoMy"),
    });
    wx.showLoading({
      title: "加载中",
    });
    setTimeout(() => {
      getProjectList({
        type: 99,
        name: this.data.INFO.jname,
        id: this.data.INFO.id,
        rybh: this.data.INFO.rybh,
        xmmc: this.data.xmmc,
        timeDown:this.data.timeDown

      }).then((res) => {
        console.log(res.data);
        this.setData({
          projectListTB: res.data,
        });
      });
      getProjectList({
        type: 89,
        name: this.data.INFO.jname,
        id: this.data.INFO.id,
        rybh: this.data.INFO.rybh,
        xmmc: this.data.xmmc,
        timeDown:this.data.timeDown

      }).then((res) => {
        this.setData({
          projectListGJ: res.data,
        });
      });
      wx.hideLoading();
    }, 500);
    console.log(this.data.INFO);
  },
  goDetail(e) {
    const { xmbh, rwbsh, xmzbh, xmzname } = e.currentTarget.dataset;
    getProjectDetail(xmbh, this.data.INFO.jname).then((res) => {
      if (res.info.length > 1) { 
        this.setData({
          xmzList:res.info,
          xmstatus: true,
        });
        console.log(this.data.xmzList)
      } else if (res.info.length == 1) {
        wx.setStorageSync("xmzbh", res.info[0].xmzbh);
        wx.setStorageSync("xmzname", res.info[0].xmzname);
        wx.navigateTo({
          url: `/pages/programs/detail/detail?xmbh=${xmbh}&rwbsh=${rwbsh}`,
        });
      }else{
        console.log(22)
        wx.navigateTo({
          url: `/pages/programs/detail/detail?xmbh=${xmbh}&rwbsh=${rwbsh}`,
        });
      }
    });
  },
  onApply(e) {
    let { node } = e.currentTarget.dataset;
    wx.setStorageSync("xmzbh", node.xmzbh);
    wx.setStorageSync("xmzname",node.xmzname);

    wx.navigateTo({
      url: `/pages/programs/detail/detail?xmbh=${node.xmbh}&rwbsh=${node.rwbsh}`,
    });
    this.onClose()
  },
  onClose() {
    this.setData({
      xmstatus: false,
      xmzList: [],
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.showLoading({
      title: "加载中",
    }),
      this.getProjectListAll();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.onLoad();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    console.log("触发下拉");
    this.getProjectListAll();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
